package com.lmiot.xyclick.Util;

import android.os.Environment;
import android.support.v4.os.EnvironmentCompat;
import android.text.TextUtils;
import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import com.lmiot.xyclick.App.MyApp;
import com.lmiot.xyclick.Bean.NewBean.DelDataBean;
import com.lmiot.xyclick.Bean.NewBean.EditUserBean;
import com.lmiot.xyclick.Bean.NewBean.FindDataBean;
import com.lmiot.xyclick.Bean.NewBean.FindDataResBean;
import com.lmiot.xyclick.Bean.NewBean.FindUserBean;
import com.lmiot.xyclick.Bean.NewBean.FindUserResBean;
import com.lmiot.xyclick.Bean.NewBean.PayAliBean;
import com.lmiot.xyclick.Bean.NewBean.PayResBean;
import com.lmiot.xyclick.Bean.NewBean.RegistBean;
import com.lmiot.xyclick.Bean.NewBean.UpdateBean;
import com.lmiot.xyclick.Bean.NewBean.WxPayBean;
import com.lmiot.xyclick.Bean.NewBean.WxPayResBean;
import com.lmiot.xyclick.Bean.SQL.AutoBeanSqlUtil;
import com.lmiot.xyclick.Bean.TaoBaoTime;
import com.lmiot.xyclick.inteface.OnBasicListener;
import com.youyi.yyviewsdklibrary.Dialog.util.ToastUtil;
import com.youyi.yyviewsdklibrary.LoadingDialog;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.builder.GetBuilder;
import com.zhy.http.okhttp.builder.PostStringBuilder;
import com.zhy.http.okhttp.callback.StringCallback;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Set;
import okhttp3.Call;
import okhttp3.MediaType;

public class HttpUtilNew {
    public static final String HOST = "https://ai.xiaoyizhineng.com:441";
    private static final String TAG = "HttpUtilNew";
    private static final HttpUtilNew ourInstance = new HttpUtilNew();

    public interface OnOffLine {
        void result(boolean z);
    }

    public interface OnPayResultListener {
        void result(boolean z, String str, PayResBean.BodyBean.DataBean dataBean);
    }

    public interface OnShareDataListener {
        void result(List<FindDataResBean.BodyBean.DataBean.BacklistBean> list);
    }

    public interface OnUserBeanListener {
        void result(boolean z);
    }

    public interface OnWxPayListener {
        void result(boolean z, WxPayResBean wxPayResBean);
    }

    public interface OndelDataListener {
        void result(boolean z);
    }

    public static HttpUtilNew getInstance() {
        return ourInstance;
    }

    private HttpUtilNew() {
    }

    public void getTime(final OnBasicListener onBasicListener) {
        ((GetBuilder) OkHttpUtils.get().url("http://api.m.taobao.com/rest/api3.do?api=mtop.common.getTimestamp")).build().execute(new StringCallback() {
            /* class com.lmiot.xyclick.Util.HttpUtilNew.AnonymousClass1 */

            @Override // com.zhy.http.okhttp.callback.Callback
           public void onError(Call call, Exception exc, int id) {
                onBasicListener.result(false, TimeUtils.getCurrentTime());
            }

            public void onResponse(String str, int id) {
                TaoBaoTime taoBaoTime = (TaoBaoTime) new Gson().fromJson(str, TaoBaoTime.class);
                if (taoBaoTime != null) {
                    onBasicListener.result(true, new SimpleDateFormat("HH:mm:ss").format(new Date(Long.parseLong(taoBaoTime.getData().getT()))));
                }
            }
        });
    }

    public void regist(final OnBasicListener onBasicListener) {
        RegistBean registBean = new RegistBean();
        RegistBean.HeadBean headBean = new RegistBean.HeadBean();
        headBean.setCmd("1001");
        headBean.setSession_id("000000000");
        headBean.setTime_stamp(System.currentTimeMillis() + "");
        RegistBean.BodyBean.ResultBean resultBean = new RegistBean.BodyBean.ResultBean();
        resultBean.setErrcode("-1");
        resultBean.setErrmsg("");
        RegistBean.BodyBean.DataBean dataBean = new RegistBean.BodyBean.DataBean();
        dataBean.setAccount_id(PhoneUtil.getIMEI(MyApp.getContext()));
        dataBean.setAccount_name(PhoneUtil.getBrand() + "");
        dataBean.setAccount_passwd("123456");
        dataBean.setDev_factory(PhoneUtil.getBrand() + "");
        dataBean.setDev_type(PhoneUtil.getModel() + "");
        dataBean.setOs_version(PhoneUtil.getSystemVersion() + "");
        dataBean.setSoft_code("XY003");
        dataBean.setSoft_version(PhoneUtil.getAPPVersion());
        dataBean.setGroup_id("reguser001");
        dataBean.setAcc_point(1000);
        dataBean.setRemark("");
        RegistBean.BodyBean bodyBean = new RegistBean.BodyBean();
        bodyBean.setData(dataBean);
        bodyBean.setResult(resultBean);
        registBean.setHead(headBean);
        registBean.setBody(bodyBean);
        LogUtil.d(TAG, "开始注册：" + "https://ai.xiaoyizhineng.com:441/user/reguser");
        LogUtil.d(TAG, "开始注册：" + new Gson().toJson(registBean));
        ((PostStringBuilder) OkHttpUtils.postString().url("https://ai.xiaoyizhineng.com:441/user/reguser")).content(new Gson().toJson(registBean)).mediaType(MediaType.parse("application/json; charset=utf-8")).build().connTimeOut(15000).writeTimeOut(15000).readTimeOut(15000).execute(new StringCallback() {
            @Override
            public void onResponse(String str, int id) {
                LogUtil.d(HttpUtilNew.TAG, "注册成功：" + str);
                DataUtil.setUserRetist(MyApp.getContext(), true);
                if (onBasicListener != null) {
                    onBasicListener.result(true, "");
                }
            }
            /* class com.lmiot.xyclick.Util.HttpUtilNew.AnonymousClass2 */

            @Override // com.zhy.http.okhttp.callback.Callback
            public void onError(Call call, Exception exc, int id) {
                if (onBasicListener != null) {
                    onBasicListener.result(false, "");
                }
                exc.printStackTrace();
            }
        });
    }

    public void editUserWx(String str, String str2, String str3, String str4, final OnBasicListener onBasicListener) {
        EditUserBean editUserBean = new EditUserBean();
        EditUserBean.HeadBean headBean = new EditUserBean.HeadBean();
        headBean.setCmd("1005");
        headBean.setSession_id("000000000");
        headBean.setTime_stamp(System.currentTimeMillis() + "");
        EditUserBean.BodyBean.ResultBean resultBean = new EditUserBean.BodyBean.ResultBean();
        resultBean.setErrcode("-1");
        resultBean.setErrmsg("");
        EditUserBean.BodyBean.DataBean dataBean = new EditUserBean.BodyBean.DataBean();
        ArrayList arrayList = new ArrayList();
        ArrayList arrayList2 = new ArrayList();
        arrayList.add("c_account_name");
        arrayList.add("c_wx_id");
        arrayList.add("c_wx_img_url");
        arrayList.add("c_phone");
        arrayList2.add(str);
        arrayList2.add(str2);
        arrayList2.add(str3);
        arrayList2.add(str4);
        dataBean.setAccount_id(PhoneUtil.getIMEI(MyApp.getContext()));
        dataBean.setFieldlist(arrayList);
        dataBean.setValuelist(arrayList2);
        EditUserBean.BodyBean bodyBean = new EditUserBean.BodyBean();
        bodyBean.setData(dataBean);
        bodyBean.setResult(resultBean);
        editUserBean.setHead(headBean);
        editUserBean.setBody(bodyBean);
        LogUtil.d(TAG, "修改信息：" + "https://ai.xiaoyizhineng.com:441/user/edtuserinfo");
        ((PostStringBuilder) OkHttpUtils.postString().url("https://ai.xiaoyizhineng.com:441/user/edtuserinfo")).content(new Gson().toJson(editUserBean)).mediaType(MediaType.parse("application/json; charset=utf-8")).build().execute(new StringCallback() {
            /* class com.lmiot.xyclick.Util.HttpUtilNew.AnonymousClass3 */

            @Override // com.zhy.http.okhttp.callback.Callback
           public void onError(Call call, Exception exc, int id) {
                if (onBasicListener != null) {
                    onBasicListener.result(false, "");
                }
                exc.printStackTrace();
            }

            public void onResponse(String str, int id) {
                LogUtil.d(HttpUtilNew.TAG, "修改信息结果：" + str);
                DataUtil.setUserRetist(MyApp.getContext(), true);
                if (onBasicListener != null) {
                    onBasicListener.result(true, "");
                }
            }
        });
    }

    public void checkVIP(String str, final OnBasicListener onBasicListener) {
        FindUserBean findUserBean = new FindUserBean();
        FindUserBean.HeadBean headBean = new FindUserBean.HeadBean();
        headBean.setCmd("1003");
        headBean.setSession_id("000000000");
        headBean.setTime_stamp(System.currentTimeMillis() + "");
        FindUserBean.BodyBean.ResultBean resultBean = new FindUserBean.BodyBean.ResultBean();
        resultBean.setErrcode("-1");
        resultBean.setErrmsg("");
        FindUserBean.BodyBean.DataBean dataBean = new FindUserBean.BodyBean.DataBean();
        dataBean.setAccount_id(str);
        FindUserBean.BodyBean bodyBean = new FindUserBean.BodyBean();
        bodyBean.setData(dataBean);
        bodyBean.setResult(resultBean);
        findUserBean.setHead(headBean);
        findUserBean.setBody(bodyBean);
        LogUtil.d(TAG, "开始查询：" + "https://ai.xiaoyizhineng.com:441/user/userinfo");
        ((PostStringBuilder) OkHttpUtils.postString().url("https://ai.xiaoyizhineng.com:441/user/userinfo")).content(new Gson().toJson(findUserBean)).mediaType(MediaType.parse("application/json; charset=utf-8")).build().execute(new StringCallback() {
            /* class com.lmiot.xyclick.Util.HttpUtilNew.AnonymousClass4 */

            @Override // com.zhy.http.okhttp.callback.Callback
           public void onError(Call call, Exception exc, int id) {
                LogUtil.d(HttpUtilNew.TAG, "查询失败：" + exc.getMessage());
                exc.printStackTrace();
            }

            public void onResponse(String str, int id) {
                LogUtil.d(HttpUtilNew.TAG, "用户信息查询成功：" + str);
                try {
                    FindUserResBean.BodyBean.DataBean data = ((FindUserResBean) new Gson().fromJson(str, FindUserResBean.class)).getBody().getData();
                    String account_id = data.getAccount_id();
                    if (!TextUtils.isEmpty(account_id) && !account_id.contains("null")) {
                        DataUtil.setUserEnable(MyApp.getContext(), data.isEnabled());
                    }
                    String vip = data.getVip();
                    if (TextUtils.isEmpty(vip)) {
                        vip = "N";
                    }
                    if (vip.equals("Y")) {
                        if (onBasicListener != null) {
                            onBasicListener.result(true, "");
                            return;
                        }
                        return;
                    }
                    OnBasicListener onBasicListener2 = onBasicListener;
                    if (onBasicListener2 != null) {
                        onBasicListener2.result(false, "");
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    public void findUserBean(final OnUserBeanListener onUserBeanListener, final OnOffLine onOffLine) {
        FindUserBean findUserBean = new FindUserBean();
        FindUserBean.HeadBean headBean = new FindUserBean.HeadBean();
        headBean.setCmd("1003");
        headBean.setSession_id("000000000");
        headBean.setTime_stamp(System.currentTimeMillis() + "");
        FindUserBean.BodyBean.ResultBean resultBean = new FindUserBean.BodyBean.ResultBean();
        resultBean.setErrcode("-1");
        resultBean.setErrmsg("");
        FindUserBean.BodyBean.DataBean dataBean = new FindUserBean.BodyBean.DataBean();
        dataBean.setAccount_id(PhoneUtil.getIMEI(MyApp.getContext()));
        FindUserBean.BodyBean bodyBean = new FindUserBean.BodyBean();
        bodyBean.setData(dataBean);
        bodyBean.setResult(resultBean);
        findUserBean.setHead(headBean);
        findUserBean.setBody(bodyBean);
        LogUtil.d(TAG, "用户信息查询：" + "https://ai.xiaoyizhineng.com:441/user/userinfo");
        ((PostStringBuilder) OkHttpUtils.postString().url("https://ai.xiaoyizhineng.com:441/user/userinfo")).content(new Gson().toJson(findUserBean)).mediaType(MediaType.parse("application/json; charset=utf-8")).build().connTimeOut(15000).writeTimeOut(15000).readTimeOut(15000).execute(new StringCallback() {
            /* class com.lmiot.xyclick.Util.HttpUtilNew.AnonymousClass5 */

            @Override // com.zhy.http.okhttp.callback.Callback
           public void onError(Call call, Exception exc, int id) {
                LogUtil.d(HttpUtilNew.TAG, "查询失败：" + exc.getMessage());
                exc.printStackTrace();
            }

            public void onResponse(String str, int id) {
                LogUtil.d(HttpUtilNew.TAG, "用户信息查询成功：" + str);
                try {
                    final FindUserResBean.BodyBean.DataBean data = ((FindUserResBean) new Gson().fromJson(str, FindUserResBean.class)).getBody().getData();
                    DataUtil.setShareFen(MyApp.getContext(), data.getAcc_point());
                    String account_id = data.getAccount_id();
                    if (!TextUtils.isEmpty(account_id) && !account_id.contains("null")) {
                        DataUtil.setUserEnable(MyApp.getContext(), data.isEnabled());
                    }
                    String str2 = "N";
                    if (DataUtil.getLoginByWx(MyApp.getContext())) {
                        String phone = data.getPhone();
                        if (TextUtils.isEmpty(phone)) {
                            DataUtil.setSessionID(MyApp.getContext(), TimeUtils.createSessionID());
                            HttpUtilNew.getInstance().editUserWx(DataUtil.getWxNickName(MyApp.getContext()), DataUtil.getWxID(MyApp.getContext()), DataUtil.getWxImg(MyApp.getContext()), DataUtil.getSessionID(MyApp.getContext()), new OnBasicListener() {
                                /* class com.lmiot.xyclick.Util.HttpUtilNew.AnonymousClass5.AnonymousClass1 */

                                @Override // com.lmiot.xyclick.inteface.OnBasicListener
                                public void result(boolean z, String str) {
                                    String vip = data.getVip();
                                    if (TextUtils.isEmpty(vip)) {
                                        vip = "N";
                                    }
                                    if (vip.equals("Y")) {
                                        DataUtil.setVip(MyApp.getContext(), true);
                                        DataUtil.setOffTime(MyApp.getContext(), data.getVip_end());
                                    } else {
                                        DataUtil.setVip(MyApp.getContext(), false);
                                        DataUtil.setOffTime(MyApp.getContext(), "");
                                    }
                                    if (onUserBeanListener != null) {
                                        onUserBeanListener.result(true);
                                    }
                                }
                            });
                        } else if (phone.equals(DataUtil.getSessionID(MyApp.getContext()))) {
                            String vip = data.getVip();
                            if (!TextUtils.isEmpty(vip)) {
                                str2 = vip;
                            }
                            if (str2.equals("Y")) {
                                DataUtil.setVip(MyApp.getContext(), true);
                                DataUtil.setOffTime(MyApp.getContext(), data.getVip_end());
                            } else {
                                DataUtil.setVip(MyApp.getContext(), false);
                                DataUtil.setOffTime(MyApp.getContext(), "");
                            }
                            if (onUserBeanListener != null) {
                                onUserBeanListener.result(true);
                            }
                        } else {
                            if (onOffLine != null) {
                                onOffLine.result(true);
                            }
                        }
                    } else {
                        String dev_type = data.getDev_type();
                        if (TextUtils.isEmpty(dev_type)) {
                            dev_type = "uknow";
                        }
                        String vip2 = data.getVip();
                        if (!TextUtils.isEmpty(vip2)) {
                            str2 = vip2;
                        }
                        if (!str2.equals("Y")) {
                            DataUtil.setVip(MyApp.getContext(), false);
                        } else if (dev_type.equals(PhoneUtil.getModel()) || dev_type.equals("123456") || dev_type.equals("uknow") || dev_type.equals(EnvironmentCompat.MEDIA_UNKNOWN)) {
                            DataUtil.setOffTime(MyApp.getContext(), data.getVip_end());
                            DataUtil.setVip(MyApp.getContext(), true);
                        } else {
                            DataUtil.setVip(MyApp.getContext(), false);
                        }
                        OnUserBeanListener onUserBeanListener2 = onUserBeanListener;
                        if (onUserBeanListener2 != null) {
                            onUserBeanListener2.result(true);
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                    OnUserBeanListener onUserBeanListener3 = onUserBeanListener;
                    if (onUserBeanListener3 != null) {
                        onUserBeanListener3.result(false);
                    }
                }
            }
        });
    }

    public void aliPay(String str, String str2, String str3, int i, String str4, String str5, final OnPayResultListener onPayResultListener) {
        PayAliBean payAliBean = new PayAliBean();
        PayAliBean.HeadBean headBean = new PayAliBean.HeadBean();
        headBean.setCmd("3001");
        headBean.setSession_id("000000000");
        headBean.setTime_stamp(System.currentTimeMillis() + "");
        PayAliBean.BodyBean.ResultBean resultBean = new PayAliBean.BodyBean.ResultBean();
        resultBean.setErrcode("-1");
        resultBean.setErrmsg("");
        PayAliBean.BodyBean.DataBean dataBean = new PayAliBean.BodyBean.DataBean();
        dataBean.setOrder_no(str);
        dataBean.setAccount_id(PhoneUtil.getIMEI(MyApp.getContext()));
        dataBean.setSoft_code("XY003");
        dataBean.setOrder_name(str2);
        dataBean.setPay_form(str3);
        dataBean.setSend_amount(i);
        dataBean.setRemark(str4);
        dataBean.setVip_level(str5);
        PayAliBean.BodyBean bodyBean = new PayAliBean.BodyBean();
        bodyBean.setData(dataBean);
        bodyBean.setResult(resultBean);
        payAliBean.setHead(headBean);
        payAliBean.setBody(bodyBean);
        LogUtil.d(TAG, "开始支付：" + "https://ai.xiaoyizhineng.com:441/pay/alisend");
        LogUtil.d(TAG, "开始支付：" + new Gson().toJson(payAliBean));
        ((PostStringBuilder) OkHttpUtils.postString().url("https://ai.xiaoyizhineng.com:441/pay/alisend")).content(new Gson().toJson(payAliBean)).mediaType(MediaType.parse("application/json; charset=utf-8")).build().execute(new StringCallback() {
            /* class com.lmiot.xyclick.Util.HttpUtilNew.AnonymousClass6 */

            @Override // com.zhy.http.okhttp.callback.Callback
           public void onError(Call call, Exception exc, int id) {
                LogUtil.d(HttpUtilNew.TAG, "支付失败：" + exc.getMessage());
                if (onPayResultListener != null) {
                    onPayResultListener.result(false, "支付失败", null);
                }
                exc.printStackTrace();
            }

            public void onResponse(String str, int id) {
                try {
                    LogUtil.d(HttpUtilNew.TAG, "支付结果：" + str);
                    PayResBean.BodyBean.DataBean data = ((PayResBean) new Gson().fromJson(str, PayResBean.class)).getBody().getData();
                    if (onPayResultListener == null) {
                        return;
                    }
                    if (data != null) {
                        onPayResultListener.result(true, "", data);
                    } else if (onPayResultListener != null) {
                        onPayResultListener.result(false, "支付失败", null);
                    }
                } catch (JsonSyntaxException e) {
                    e.printStackTrace();
                    OnPayResultListener onPayResultListener2 = onPayResultListener;
                    if (onPayResultListener2 != null) {
                        onPayResultListener2.result(false, "支付失败", null);
                    }
                }
            }
        });
    }

    public void wxpay(String str, String str2, String str3, String str4, int i, String str5, String str6, final OnWxPayListener onWxPayListener) {
        WxPayBean wxPayBean = new WxPayBean();
        WxPayBean.HeadBean headBean = new WxPayBean.HeadBean();
        headBean.setCmd("3001");
        headBean.setSession_id("000000000");
        headBean.setTime_stamp(System.currentTimeMillis() + "");
        WxPayBean.BodyBean.ResultBean resultBean = new WxPayBean.BodyBean.ResultBean();
        resultBean.setErrcode("-1");
        resultBean.setErrmsg("");
        WxPayBean.BodyBean.DataBean dataBean = new WxPayBean.BodyBean.DataBean();
        dataBean.setApp_id(str);
        dataBean.setOrder_no(str2);
        dataBean.setAccount_id(PhoneUtil.getIMEI(MyApp.getContext()));
        dataBean.setSoft_code("XY001");
        dataBean.setOrder_name(str3);
        dataBean.setPay_form(str4);
        dataBean.setSend_amount(i);
        dataBean.setRemark(str5);
        dataBean.setVip_level(str6);
        WxPayBean.BodyBean bodyBean = new WxPayBean.BodyBean();
        bodyBean.setData(dataBean);
        bodyBean.setResult(resultBean);
        wxPayBean.setHead(headBean);
        wxPayBean.setBody(bodyBean);
        ((PostStringBuilder) OkHttpUtils.postString().url("https://ai.xiaoyizhineng.com:441/pay/wxsend")).content(new Gson().toJson(wxPayBean)).mediaType(MediaType.parse("application/json; charset=utf-8")).build().execute(new StringCallback() {
            /* class com.lmiot.xyclick.Util.HttpUtilNew.AnonymousClass7 */

            @Override // com.zhy.http.okhttp.callback.Callback
           public void onError(Call call, Exception exc, int id) {
                exc.printStackTrace();
                onWxPayListener.result(false, null);
            }

            public void onResponse(String str, int id) {
                LogUtil.d(HttpUtilNew.TAG, str);
                try {
                    onWxPayListener.result(true, (WxPayResBean) new Gson().fromJson(str, WxPayResBean.class));
                } catch (Exception e) {
                    e.printStackTrace();
                    onWxPayListener.result(false, null);
                }
            }
        });
    }

    public void delFile(String str, final OndelDataListener ondelDataListener) {
        DelDataBean delDataBean = new DelDataBean();
        DelDataBean.HeadBean headBean = new DelDataBean.HeadBean();
        headBean.setCmd("1001");
        headBean.setSession_id("000000000");
        headBean.setTime_stamp(System.currentTimeMillis() + "");
        DelDataBean.BodyBean.ResultBean resultBean = new DelDataBean.BodyBean.ResultBean();
        resultBean.setErrcode("-1");
        resultBean.setErrmsg("");
        DelDataBean.BodyBean.DataBean dataBean = new DelDataBean.BodyBean.DataBean();
        dataBean.setAccount_id(MyApp.getContext().getPackageName());
        dataBean.setBack_id(str);
        DelDataBean.BodyBean bodyBean = new DelDataBean.BodyBean();
        bodyBean.setData(dataBean);
        bodyBean.setResult(resultBean);
        delDataBean.setHead(headBean);
        delDataBean.setBody(bodyBean);
        ((PostStringBuilder) OkHttpUtils.postString().url("https://ai.xiaoyizhineng.com:441/bak/delbak")).content(new Gson().toJson(delDataBean)).mediaType(MediaType.parse("application/json; charset=utf-8")).build().execute(new StringCallback() {
            /* class com.lmiot.xyclick.Util.HttpUtilNew.AnonymousClass8 */

            @Override // com.zhy.http.okhttp.callback.Callback
           public void onError(Call call, Exception exc, int id) {
                exc.printStackTrace();
                ondelDataListener.result(false);
            }

            public void onResponse(String str, int id) {
                ondelDataListener.result(true);
            }
        });
    }

    public void upLoadBackFile() {
        try {
            final String currentTime = TimeUtils.getCurrentTime();
            String str = MyApp.getContext().getPackageName() + "_" + PhoneUtil.getIMEI(MyApp.getContext()) + "_BackUpFile";
            String str2 = MyApp.getContext().getPackageName() + "_" + PhoneUtil.getIMEI(MyApp.getContext());
            String str3 = PhoneUtil.getIMEI(MyApp.getContext()) + "备份文件，包含：" + AutoBeanSqlUtil.getInstance().searchAll().size() + "个自动化数据";
            String str4 = PhoneUtil.getBrand() + "#" + PhoneUtil.getModel() + "#" + MyApp.mWidth + "#" + MyApp.mHeight;
            File file = new File(Environment.getExternalStorageDirectory() + "/XYClick", "XYClick.zip");
            if (!file.exists()) {
                file.createNewFile();
            }
//            upLoadFile(str2, str, str3, str4, FileUtils.fileToBase64String(file.getAbsolutePath()), new OnBasicListener() {
//                /* class com.lmiot.xyclick.Util.HttpUtilNew.AnonymousClass9 */
//
//                @Override // com.lmiot.xyclick.inteface.OnBasicListener
//                public void result(boolean z, String str) {
//                    LoadingDialog.hidden();
//                    if (z) {
//                        ToastUtil.success("备份成功！");
//                        DataUtil.setRecentBackFile(MyApp.getContext(), currentTime);
//                        return;
//                    }
//                    ToastUtil.err("备份失败！");
//                }
//            });
        } catch (Exception e) {
            LoadingDialog.hidden();
            e.printStackTrace();
            ToastUtil.err("读取数据错误！");
        }
    }

    public void upLoadFile(String str, String str2, String str3, String str4, String str5, final OnBasicListener onBasicListener) {
        UpdateBean updateBean = new UpdateBean();
        UpdateBean.HeadBean headBean = new UpdateBean.HeadBean();
        headBean.setCmd("1001");
        headBean.setSession_id("000000000");
        headBean.setTime_stamp(System.currentTimeMillis() + "");
        UpdateBean.BodyBean.ResultBean resultBean = new UpdateBean.BodyBean.ResultBean();
        resultBean.setErrcode("-1");
        resultBean.setErrmsg("");
        UpdateBean.BodyBean.DataBean dataBean = new UpdateBean.BodyBean.DataBean();
        dataBean.setBack_id(str);
        dataBean.setAccount_id(PhoneUtil.getIMEI(MyApp.getContext()));
        dataBean.setFile_name(str2);
        dataBean.setFile_note(str3);
        dataBean.setFile_context(str5);
        dataBean.setSoft_code("XY001");
        dataBean.setSoft_version_code(PhoneUtil.getAPPVersion() + "");
        dataBean.setEnabled_down(1);
        dataBean.setNeed_acc_point(0);
        dataBean.setRemark(str4);
        UpdateBean.BodyBean bodyBean = new UpdateBean.BodyBean();
        bodyBean.setData(dataBean);
        bodyBean.setResult(resultBean);
        updateBean.setHead(headBean);
        updateBean.setBody(bodyBean);
        ((PostStringBuilder) OkHttpUtils.postString().url("https://ai.xiaoyizhineng.com:441/bak/bakinfo")).content(new Gson().toJson(updateBean)).mediaType(MediaType.parse("application/json; charset=utf-8")).build().execute(new StringCallback() {
            /* class com.lmiot.xyclick.Util.HttpUtilNew.AnonymousClass10 */

            @Override // com.zhy.http.okhttp.callback.Callback
           public void onError(Call call, Exception exc, int id) {
                LogUtil.d(HttpUtilNew.TAG, "备份失败：" + exc.getMessage());
                onBasicListener.result(false, "");
                exc.printStackTrace();
            }

            public void onResponse(String str, int id) {
                LogUtil.d(HttpUtilNew.TAG, "备份成功：" + str);
                onBasicListener.result(true, "");
            }
        });
    }

    public void searchBckFile(String str, final OnShareDataListener onShareDataListener) {
        FindDataBean findDataBean = new FindDataBean();
        FindDataBean.HeadBean headBean = new FindDataBean.HeadBean();
        headBean.setCmd("1001");
        headBean.setSession_id("000000000");
        headBean.setTime_stamp(System.currentTimeMillis() + "");
        FindDataBean.BodyBean.ResultBean resultBean = new FindDataBean.BodyBean.ResultBean();
        resultBean.setErrcode("-1");
        resultBean.setErrmsg("");
        FindDataBean.BodyBean.DataBean dataBean = new FindDataBean.BodyBean.DataBean();
        dataBean.setAccount_id(str);
        dataBean.setFile_name(MyApp.getContext().getPackageName() + "_" + str + "_BackUpFile");
        FindDataBean.BodyBean bodyBean = new FindDataBean.BodyBean();
        bodyBean.setData(dataBean);
        bodyBean.setResult(resultBean);
        findDataBean.setHead(headBean);
        findDataBean.setBody(bodyBean);
        ((PostStringBuilder) OkHttpUtils.postString().url("https://ai.xiaoyizhineng.com:441/bak/getbak")).content(new Gson().toJson(findDataBean)).mediaType(MediaType.parse("application/json; charset=utf-8")).build().execute(new StringCallback() {
            /* class com.lmiot.xyclick.Util.HttpUtilNew.AnonymousClass11 */

            @Override // com.zhy.http.okhttp.callback.Callback
           public void onError(Call call, Exception exc, int id) {
                LogUtil.d(HttpUtilNew.TAG, "查询备份失败：" + exc.getMessage());
                exc.printStackTrace();
            }

            public void onResponse(String str, int id) {
                LogUtil.d(HttpUtilNew.TAG, "查询备份成功：" + str);
                try {
                    onShareDataListener.result(((FindDataResBean) new Gson().fromJson(str, FindDataResBean.class)).getBody().getData().getBacklist());
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    public void downAllShare(String str, String str2, final OnShareDataListener onShareDataListener) {
        FindDataBean findDataBean = new FindDataBean();
        FindDataBean.HeadBean headBean = new FindDataBean.HeadBean();
        headBean.setCmd("1001");
        headBean.setSession_id("000000000");
        headBean.setTime_stamp(System.currentTimeMillis() + "");
        FindDataBean.BodyBean.ResultBean resultBean = new FindDataBean.BodyBean.ResultBean();
        resultBean.setErrcode("-1");
        resultBean.setErrmsg("");
        FindDataBean.BodyBean.DataBean dataBean = new FindDataBean.BodyBean.DataBean();
        dataBean.setAccount_id(str);
        dataBean.setFile_name(str2);
        FindDataBean.BodyBean bodyBean = new FindDataBean.BodyBean();
        bodyBean.setData(dataBean);
        bodyBean.setResult(resultBean);
        findDataBean.setHead(headBean);
        findDataBean.setBody(bodyBean);
        ((PostStringBuilder) OkHttpUtils.postString().url("https://ai.xiaoyizhineng.com:441/bak/getbak")).content(new Gson().toJson(findDataBean)).mediaType(MediaType.parse("application/json; charset=utf-8")).build().execute(new StringCallback() {
            /* class com.lmiot.xyclick.Util.HttpUtilNew.AnonymousClass12 */

            @Override // com.zhy.http.okhttp.callback.Callback
           public void onError(Call call, Exception exc, int id) {
                LogUtil.d(HttpUtilNew.TAG, "查询备份失败：" + exc.getMessage());
                exc.printStackTrace();
            }

            public void onResponse(String str, int id) {
                LogUtil.d(HttpUtilNew.TAG, "查询备份成功：" + str);
                try {
                    onShareDataListener.result(((FindDataResBean) new Gson().fromJson(str, FindDataResBean.class)).getBody().getData().getBacklist());
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    public void upLoadAutoFile(String str, final OnBasicListener onBasicListener) {
        try {
            FileUtils.saveToLocalData(str, new OnBasicListener() {
                /* class com.lmiot.xyclick.Util.HttpUtilNew.AnonymousClass13 */

                @Override // com.lmiot.xyclick.inteface.OnBasicListener
                public void result(boolean z, String str) {
                }
            });
            File file = new File(Environment.getExternalStorageDirectory() + "/XYClick/data", str + "." + DataUtil.FILE_XYCLICK_DATA);
            if (!file.exists()) {
                file.createNewFile();
            }
            String str2 = PhoneUtil.getIMEI(MyApp.getContext()) + "_" + str;
            String str3 = PhoneUtil.getIMEI(MyApp.getContext()) + "_autoclickfile_" + str;
            String fileToBase64String = FileUtils.fileToBase64String(file.getAbsolutePath());
            UpdateBean updateBean = new UpdateBean();
            UpdateBean.HeadBean headBean = new UpdateBean.HeadBean();
            headBean.setCmd("1001");
            headBean.setSession_id("000000000");
            headBean.setTime_stamp(System.currentTimeMillis() + "");
            UpdateBean.BodyBean.ResultBean resultBean = new UpdateBean.BodyBean.ResultBean();
            resultBean.setErrcode("-1");
            resultBean.setErrmsg("");
            UpdateBean.BodyBean.DataBean dataBean = new UpdateBean.BodyBean.DataBean();
            dataBean.setBack_id(str2);
            dataBean.setAccount_id(MyApp.getContext().getPackageName());
            dataBean.setFile_name(str3);
            dataBean.setFile_note("连点器分享自动化");
            dataBean.setFile_context(fileToBase64String);
            dataBean.setSoft_code("XY003");
            dataBean.setSoft_version_code(PhoneUtil.getAPPVersion() + "");
            dataBean.setEnabled_down(1);
            dataBean.setNeed_acc_point(0);
            dataBean.setRemark(AutoBeanSqlUtil.getInstance().searchByID(str).getAutoName() + "");
            UpdateBean.BodyBean bodyBean = new UpdateBean.BodyBean();
            bodyBean.setData(dataBean);
            bodyBean.setResult(resultBean);
            updateBean.setHead(headBean);
            updateBean.setBody(bodyBean);
            ((PostStringBuilder) OkHttpUtils.postString().url("https://ai.xiaoyizhineng.com:441/bak/bakinfo")).content(new Gson().toJson(updateBean)).mediaType(MediaType.parse("application/json; charset=utf-8")).build().execute(new StringCallback() {
                /* class com.lmiot.xyclick.Util.HttpUtilNew.AnonymousClass14 */

                @Override // com.zhy.http.okhttp.callback.Callback
               public void onError(Call call, Exception exc, int id) {
                    LogUtil.d(HttpUtilNew.TAG, "上传失败：" + exc.getMessage());
                    exc.printStackTrace();
                    if (onBasicListener != null) {
                        onBasicListener.result(false, "");
                    }
                }

                public void onResponse(String str, int id) {
                    LogUtil.d(HttpUtilNew.TAG, "上传成功：" + str);
                    if (onBasicListener != null) {
                        onBasicListener.result(true, "");
                    }
                }
            });
        } catch (Exception e) {
            e.printStackTrace();
            if (onBasicListener != null) {
                onBasicListener.result(false, "");
            }
        }
    }

    public void downAutoFile(String str, String str2, final OnShareDataListener onShareDataListener) {
        String str3 = str + "_autoclickfile_" + str2;
        FindDataBean findDataBean = new FindDataBean();
        FindDataBean.HeadBean headBean = new FindDataBean.HeadBean();
        headBean.setCmd("1001");
        headBean.setSession_id("000000000");
        headBean.setTime_stamp(System.currentTimeMillis() + "");
        FindDataBean.BodyBean.ResultBean resultBean = new FindDataBean.BodyBean.ResultBean();
        resultBean.setErrcode("-1");
        resultBean.setErrmsg("");
        FindDataBean.BodyBean.DataBean dataBean = new FindDataBean.BodyBean.DataBean();
        dataBean.setAccount_id(MyApp.getContext().getPackageName());
        dataBean.setFile_name(str3);
        FindDataBean.BodyBean bodyBean = new FindDataBean.BodyBean();
        bodyBean.setData(dataBean);
        bodyBean.setResult(resultBean);
        findDataBean.setHead(headBean);
        findDataBean.setBody(bodyBean);
        LogUtil.d(TAG, "下载备份：" + "https://ai.xiaoyizhineng.com:441/bak/getbak");
        String json = new Gson().toJson(findDataBean);
        LogUtil.d(TAG, "下载备份：" + json);
        ((PostStringBuilder) OkHttpUtils.postString().url("https://ai.xiaoyizhineng.com:441/bak/getbak")).content(json).mediaType(MediaType.parse("application/json; charset=utf-8")).build().execute(new StringCallback() {
            /* class com.lmiot.xyclick.Util.HttpUtilNew.AnonymousClass15 */

            @Override // com.zhy.http.okhttp.callback.Callback
           public void onError(Call call, Exception exc, int id) {
                LogUtil.d(HttpUtilNew.TAG, "下载备份失败：" + exc.getMessage());
                exc.printStackTrace();
                if (onShareDataListener != null) {
                    onShareDataListener.result(null);
                }
            }

            public void onResponse(String str, int id) {
                LogUtil.d(HttpUtilNew.TAG, "下载备份成功：" + str);
                try {
                    onShareDataListener.result(((FindDataResBean) new Gson().fromJson(str, FindDataResBean.class)).getBody().getData().getBacklist());
                } catch (Exception e) {
                    e.printStackTrace();
                    onShareDataListener.result(null);
                }
            }
        });
    }

    public void freshPoint(final OnBasicListener onBasicListener) {
        FindUserBean findUserBean = new FindUserBean();
        FindUserBean.HeadBean headBean = new FindUserBean.HeadBean();
        headBean.setCmd("1003");
        headBean.setSession_id("000000000");
        headBean.setTime_stamp(System.currentTimeMillis() + "");
        FindUserBean.BodyBean.ResultBean resultBean = new FindUserBean.BodyBean.ResultBean();
        resultBean.setErrcode("-1");
        resultBean.setErrmsg("");
        FindUserBean.BodyBean.DataBean dataBean = new FindUserBean.BodyBean.DataBean();
        dataBean.setAccount_id(PhoneUtil.getIMEI(MyApp.getContext()));
        FindUserBean.BodyBean bodyBean = new FindUserBean.BodyBean();
        bodyBean.setData(dataBean);
        bodyBean.setResult(resultBean);
        findUserBean.setHead(headBean);
        findUserBean.setBody(bodyBean);
        ((PostStringBuilder) OkHttpUtils.postString().url("https://ai.xiaoyizhineng.com:441/user/userinfo")).content(new Gson().toJson(findUserBean)).mediaType(MediaType.parse("application/json; charset=utf-8")).build().execute(new StringCallback() {
            /* class com.lmiot.xyclick.Util.HttpUtilNew.AnonymousClass16 */

            @Override // com.zhy.http.okhttp.callback.Callback
           public void onError(Call call, Exception exc, int id) {
                exc.printStackTrace();
            }

            public void onResponse(String str, int id) {
                try {
                    FindUserResBean.BodyBean.DataBean data = ((FindUserResBean) new Gson().fromJson(str, FindUserResBean.class)).getBody().getData();
                    DataUtil.setShareFen(MyApp.getContext(), data.getAcc_point());
                    String account_id = data.getAccount_id();
                    if (!TextUtils.isEmpty(account_id) && !account_id.contains("null")) {
                        DataUtil.setUserEnable(MyApp.getContext(), data.isEnabled());
                    }
                    if (onBasicListener == null) {
                        return;
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                    if (onBasicListener == null) {
                        return;
                    }
                } catch (Throwable th) {
                    OnBasicListener onBasicListener2 = onBasicListener;
                    if (onBasicListener2 != null) {
                        onBasicListener2.result(true, "");
                    }
                    throw th;
                }
                onBasicListener.result(true, "");
            }
        });
    }

    public void shareAll(String str, String str2, final Set<String> set) {
        try {
            final String str3 = MyApp.getContext().getPackageName() + "_" + PhoneUtil.getIMEI(MyApp.getContext()) + str2;
            String str4 = MyApp.getContext().getPackageName() + "_" + PhoneUtil.getIMEI(MyApp.getContext());
            String str5 = PhoneUtil.getIMEI(MyApp.getContext()) + "备份文件，包含：" + AutoBeanSqlUtil.getInstance().searchAll().size() + "个自动化数据";
            String str6 = PhoneUtil.getBrand() + "#" + PhoneUtil.getModel() + "#" + MyApp.mWidth + "#" + MyApp.mHeight;
            File file = new File(str);
            if (!file.exists()) {
                file.createNewFile();
            }
            getInstance().upLoadFile(str4, str3, str5, str6, FileUtils.fileToBase64String(file.getAbsolutePath()), new OnBasicListener() {
                /* class com.lmiot.xyclick.Util.HttpUtilNew.AnonymousClass17 */

                @Override // com.lmiot.xyclick.inteface.OnBasicListener
                public void result(boolean z, String str) {
                    LoadingDialog.hidden();
                    if (z) {
//                        PushUtils instance = PushUtils.getInstance();
//                        PushTemplate.PushType pushType = PushTemplate.PushType.NoticAndExtra;
//                        Set<String> set = set;
//                        instance.pushList(pushType, set, "收到自动化数据包", "来自用户：" + PhoneUtil.getIMEI(MyApp.getContext()), PushUtils.getInstance().getAdminExtraString(PushUtils.PUSH_TYPE_SHARE_ALL, str3), new OnBasicListener() {
//                            /* class com.lmiot.xyclick.Util.HttpUtilNew.AnonymousClass17.AnonymousClass1 */
//
//                            @Override // com.lmiot.xyclick.inteface.OnBasicListener
//                            public void result(boolean z, String str) {
//                                LogUtil.d(HttpUtilNew.TAG, "个推：推送结果：isSuccess:" + z);
//                                LoadingDialog.hidden();
//                                if (z) {
//                                    ToastUtil.success("分享成功");
//                                } else {
//                                    ToastUtil.err("分享失败");
//                                }
//                            }
//                        });
                        return;
                    }
                    ToastUtil.err("上传失败");
                }
            });
        } catch (Exception e) {
            LoadingDialog.hidden();
            e.printStackTrace();
            ToastUtil.err("读取数据错误！");
        }
    }
}
